package cn.com.infosec.ra.service.user;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.com.infosec.ra.dao.logdao.LogDao;
import cn.com.infosec.ra.dao.userdao.UserDao;
import cn.com.infosec.ra.entity.AdminOperatorEntity;
import cn.com.infosec.ra.entity.LogEntity;
import cn.com.infosec.ra.util.Pagination;

@Service
@Transactional
public class UserServiceImpl implements UserService {
	
	@Resource
	private UserDao userDao;
	
	@Resource
	private LogDao logDao;
	
	@Override
	public AdminOperatorEntity getAdminOperator(String operatoraccount) {
		return userDao.getOperator(operatoraccount);
	}
	
	@Override
	public void saveAdminOP(AdminOperatorEntity adminOP) {
		userDao.saveAdminOP(adminOP);
	}

	@Override
	public void saveAdminOP(AdminOperatorEntity adminOP, LogEntity log){
		userDao.saveAdminOP(adminOP);
		logDao.saveLog(log);
	}

	@Override
	public void updateAdminOperator(AdminOperatorEntity adminOP) {
		userDao.updateAdminOperator(adminOP);
		
	}

	@Override
	public Pagination<AdminOperatorEntity> queryUserByPager(String operatorType,
			int operatorOrganid, Pagination<AdminOperatorEntity> pager) {
		List<AdminOperatorEntity> userList = userDao.queryUserByPager(operatorType,
				operatorOrganid, pager);
		List<AdminOperatorEntity> userListAll = userDao.queryUser(operatorType, operatorOrganid);
		pager.setItems(userList);
		pager.setCount(userListAll.size());
		return pager;
	}

	@Override
	public Pagination<AdminOperatorEntity> queryUserByPagerOracle(
			String operatorType, int operatorOrganid,
			Pagination<AdminOperatorEntity> pager) {
		List<AdminOperatorEntity> userList = userDao.queryUserByPagerOracle(operatorType,
				operatorOrganid, pager);
		List<AdminOperatorEntity> userListAll = userDao.queryUser(operatorType, operatorOrganid);
		pager.setItems(userList);
		pager.setCount(userListAll.size());
		return pager;
	}

}
